package person.learn;

import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import person.learn.interceptors.URLInterceptor;

/**
 * Created by barton on 16-1-25.
 * 1.@EnableWebMvc
 */
@SpringBootApplication
@RestController
//@EnableAsync
//@EnableWebMvc
public class SpringBootLearnApplication extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
        // args : 传递给SpringApplication的构造器参数是spring
        // beans的配置源。在大多数情况下，这些将是@Configuration类的引用，但它们也可能是XML配置或要扫描包的引用
        SpringApplication.run(SpringBootLearnApplication.class, args);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new URLInterceptor()).addPathPatterns("/interceptor/beilanjie");
    }

    @RequestMapping("/hello")
    public JSONObject hello() {
        JSONObject object = new JSONObject();
        object.put("name", "springboot");
        object.put("age", "26");
        object.put("description", "Hello World! Hello Spring-Boot!");
        return object;
    }
    
    @RequestMapping("/hello1")
    public String hello1() {
        return "Hello World! Hello Spring-Boot!";
    }
}
